package com.lzc.springboot.mapper;

import com.lzc.springboot.domain.User;
import org.apache.ibatis.annotations.*;

@Mapper
public interface UserMapper {

  /**
   * 根据账号密码查询用户
   * @param user
   * @return
   */
  @Select("select * from users where username=#{username} and password=#{password}")
  @Options(useCache = false, flushCache = Options.FlushCachePolicy.TRUE)
  User findByNameAndPwd(User user);

  /**
   * 根据用户id修改账号、密码
   * @param user
   */
  @Update("update users set username=#{username},password=#{password} where id=#{id}")
  void changeUser(User user);

  /**
   * 根据用户ID查询用户
   * @param id
   * @return
   */
  @Select("select * from users where id=#{id}")
  @Options(useCache = false,flushCache = Options.FlushCachePolicy.TRUE)
  User findUserById(int id);

  /**
   * 根据用户ID删除用户
   * @param id
   */
  @Delete("delete from users where id=#{id}")
  void delUserById(int id);

  /**
   * 专家审核通过
   * @param id
   */
  @Update("update users set checked='1' where id=#{id}")
  void expertChecked(int id);

  /**
   * 专家审核未通过
   * @param id
   */
  @Update("update users set checked='2' where id=#{id}")
  void expertUnChecked(int id);

  /**
   * 注册用户
   * @param user
   */
  @Insert("insert into users values(null,#{username},#{password},#{role},#{checked})")
  @Options(useGeneratedKeys=true, keyProperty="id", keyColumn="id")
  void register(User user);

  /**
   * 根据用户名查询用户
   * @param username
   * @return
   */
  @Select("select * from users where username=#{username}")
  @Options(useCache = false,flushCache = Options.FlushCachePolicy.TRUE)
  User findByUsername(String username);
}
